/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.cas.test.aqs;

import java.util.LinkedList;
import java.util.List;

//生产者(写入线程)
public class SynchronizedProviderDemo implements Runnable {

    public static List<String> cache = new LinkedList<String>();

    @Override
    public void run() {
        try {
            while (!Thread.interrupted()) {
                Thread.sleep(10);
                synchronized (cache) {
                    if (cache.size() < 1) {
                        System.out.println("生产bread");
                        cache.add(new String("bread"));
                        cache.notifyAll();
                    } else {
                        System.out.println("bread生产超过总量");
                        cache.wait();
                    }
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}